package com.lishe.lishe.lishe.module.excitation.presenter;

import android.text.TextUtils;

import com.lishe.lishe.lishe.bean.DianZanObject;
import com.lishe.lishe.lishe.common.Globals;
import com.lishe.lishe.lishe.module.excitation.bean.AchievementObject;
import com.lishe.lishe.lishe.module.excitation.bean.CommentObject;
import com.lishe.lishe.lishe.module.excitation.bean.MineExcitationObject;
import com.lishe.lishe.lishe.module.excitation.bean.PersonImpression;
import com.lishe.lishe.lishe.module.excitation.bean.PersonInfoObject;
import com.lishe.lishe.lishe.module.excitation.bean.UserIntegralObject;
import com.lishe.lishe.lishe.module.excitation.interfaces.ExcitationService;
import com.lishe.lishe.lishe.utils.StringUtils;
import com.lishe.lishe.retrofit.BaseDataPageBody;
import com.lishe.lishe.retrofit.BaseRequestBody;
import com.lishe.lishe.retrofit.DataResponseListener;
import com.lishe.lishe.retrofit.RetrofitFactory;
import com.lishe.lishe.retrofit.bean.InfoArrayObject;
import com.lishe.lishe.retrofit.bean.InfoObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by yang on 2017/12/13.
 */

public class MinePresenter {

    private static MinePresenter presenter;

    public static MinePresenter getInstance() {
        if (presenter == null) {
            presenter = new MinePresenter();
        }
        return presenter;
    }

    /**
     * 激励模块-个人中心-获取用户信息
     *
     * @param token
     * @param userId
     * @param listener
     */
    public void getUserInfo(String token, String userId, final DataResponseListener<PersonInfoObject> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }
        signParams.put("token", token);
        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getUserInfo(token, userId, sign)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<InfoObject<PersonInfoObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<InfoObject<PersonInfoObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData().getInfo());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-个人中心-获取用户成就列表
     *
     * @param token
     * @param userId
     * @param listener
     */
    public void getUserAchieveList(String token, String userId ,int num ,final DataResponseListener<List<MineExcitationObject>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }
        signParams.put("token", token);
        signParams.put("num", String.valueOf(num));
        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getUserAchieveList(token, userId, sign,num)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<InfoArrayObject<MineExcitationObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<InfoArrayObject<MineExcitationObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData().getInfo());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-个人中心-获取用户小礼列表
     *
     * @param token
     * @param userId
     * @param listener
     */
    public void getUserGifts(String token, String userId,int pageNo,int pageSize,int num ,final DataResponseListener<BaseDataPageBody<MineExcitationObject>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }
        signParams.put("pageNo", String.valueOf(pageNo));
        signParams.put("pageSize", String.valueOf(pageSize));
        signParams.put("num", String.valueOf(num));

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getUserGifts(token, userId,pageNo,pageSize, sign,num)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<BaseDataPageBody<MineExcitationObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<BaseDataPageBody<MineExcitationObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-个人中心-兑换小礼
     *
     * @param token
     * @param exchangeGiftIds
     * @param listener
     */
    public void exchangeGift(String token, String exchangeGiftIds, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("exchangeGiftIds",exchangeGiftIds);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .exchangeGift(token, exchangeGiftIds, sign)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-个人中心-兑换小礼
     *
     * @param token
     * @param listener
     */
    public void searchEncourageGifts(String token, final DataResponseListener<List<MineExcitationObject>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .searchEncourageGifts(token, sign)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<InfoArrayObject<MineExcitationObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<InfoArrayObject<MineExcitationObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData().getInfo());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 获取用户积分
     *
     * @param token
     * @param listener
     */
    public void getUserIntegral(String token, final DataResponseListener<UserIntegralObject> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.create().create(ExcitationService.class)
                .getUserIntegral(token, sign)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<UserIntegralObject>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<UserIntegralObject> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-赠送小礼
     *
     * @param token
     * @param eventUserId
     * @param listener
     */
    public void sendGift(String token, String eventUserId,String giftId,String eventId,String pointsType, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventUserId", eventUserId);
        signParams.put("giftId", giftId);
        signParams.put("eventId", eventId);
        signParams.put("pointsType", pointsType);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .sendGift(token, sign,giftId,eventUserId,eventId,pointsType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-成就详情
     *
     * @param token
     * @param userId
     * @param listener
     */
    private Disposable mDisposable;
    public void getAchieveDetail(String token, String userId,String achieveId, final DataResponseListener<AchievementObject> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }
        signParams.put("achieveId", achieveId);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getAchieveDetail(token, sign,userId,achieveId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<InfoObject<AchievementObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        if(mDisposable!=null) mDisposable.dispose();
                        listener.onPrepare();
                        mDisposable=d;
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<InfoObject<AchievementObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData().getInfo());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-成就详情
     *
     * @param token
     * @param userId
     * @param listener
     */
    public void receiveAchieveAward(String token, String userId,String achieveId, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }
        signParams.put("achieveId", achieveId);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .receiveAchieveAward(token,sign,userId,achieveId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-成就详情
     *
     * @param token
     * @param forwardChannel
     * @param listener
     */
    public void shareAchievement(String token, String forwardChannel,String achieveId, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("forwardChannel", forwardChannel);
        signParams.put("achieveId", achieveId);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .shareAchievement(token,sign,forwardChannel,achieveId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-添加评论
     *
     * @param token
     * @param eventId
     * @param listener
     */
    public void addEventComment(String token, String eventComment,String eventId, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventComment", eventComment);
        signParams.put("eventId", eventId);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .addEventComment(token,sign,eventComment,eventId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-添加评论
     *
     * @param token
     * @param listener
     */
    public void getUserEventList(String token, String userId, String type, String pageNo, String pageSize, final DataResponseListener<BaseDataPageBody<DianZanObject>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }
        signParams.put("type", type);
        signParams.put("pageNo", pageNo);
        signParams.put("pageSize", pageSize);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getUserEventList(token,sign,userId,type,pageNo,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<BaseDataPageBody<DianZanObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<BaseDataPageBody<DianZanObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-获取用户个人印象
     *
     * @param token
     * @param listener
     */
    public void getUserActionList(String token, String userId, final DataResponseListener<List<PersonImpression>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        if (!TextUtils.isEmpty(userId)) {
            signParams.put("userId", userId);
        }

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getUserActionList(token,sign,userId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<InfoArrayObject<PersonImpression>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<InfoArrayObject<PersonImpression>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData().getInfo());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-获取点赞详情
     *
     * @param token
     * @param listener
     */
    public void getEventDetail(String token, String eventId, final DataResponseListener<DianZanObject> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventId",eventId);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getEventDetail(token,sign,eventId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<InfoObject<DianZanObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<InfoObject<DianZanObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData().getInfo());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-获取评论列表
     *
     * @param token
     * @param listener
     */
    public void getEventCommentList(String token, String eventId,String pageNo, String pageSize, final DataResponseListener<BaseDataPageBody<CommentObject>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventId",eventId);
        signParams.put("pageNo", pageNo);
        signParams.put("pageSize", pageSize);

        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .getEventCommentList(token,sign,eventId,pageNo,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<BaseDataPageBody<CommentObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<BaseDataPageBody<CommentObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-事件鼓励
     *
     * @param token
     * @param eventId
     * @param listener
     */
    public void hitEvent(String token,String eventId, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventId", eventId);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .hitEvent(token,sign,eventId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    /**
     * 激励模块-取消事件鼓励
     *
     * @param token
     * @param eventId
     * @param listener
     */
    public void cancelHitEvent(String token,String eventId, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventId", eventId);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .cancelHitEvent(token,sign,eventId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 激励模块-添加评论
     *
     * @param token
     * @param listener
     */
    public void eventList(String token, String pageNo,String pageSize, final DataResponseListener<BaseDataPageBody<DianZanObject>> listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("pageNo", pageNo);
        signParams.put("pageSize", pageSize);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .eventList(token,sign,pageNo,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody<BaseDataPageBody<DianZanObject>>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody<BaseDataPageBody<DianZanObject>> requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getData());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

    /**
     * 激励模块-取消事件鼓励
     *
     * @param token
     * @param eventId
     * @param listener
     */
    public void shareEvent(String token,String eventId, String forwardChannel, final DataResponseListener listener) throws Exception{
        Map<String, String> signParams = new HashMap<>();
        signParams.put("token", token);
        signParams.put("eventId", eventId);
        signParams.put("forwardChannel", forwardChannel);


        String sign = StringUtils.createSignString(signParams) + Globals.key;
        sign = StringUtils.md5(sign);

        RetrofitFactory.createExcitationUrl().create(ExcitationService.class)
                .shareEvent(token,sign,forwardChannel,eventId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseRequestBody>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        listener.onPrepare();
                    }

                    @Override
                    public void onNext(@NonNull BaseRequestBody requestBody) {
                        if (requestBody.getResult() == 100 && requestBody.getErrcode() == 0) {
                            listener.onSuccess(requestBody.getMsg());
                        } else {
                            listener.onFail(requestBody.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        listener.onError(e);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
